package com.ff.xyh.consumer.messagedeliver.config;

import com.ff.xyh.consumer.messagedeliver.listener.OrderReceiver;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author laoliangliang
 * @date 2019/3/29 11:41
 */
//@Configuration
//@ConditionalOnProperty(name="websocket.enabled",havingValue = "true")
public class RabbitmqConfig {

//    final public static String EXCHANGENAME = "websocketExchange";
//
//    /**
//     * 创建交换器
//     */
//    @Bean
//    FanoutExchange exchange() {
//        return new FanoutExchange(EXCHANGENAME);
//    }
//
//    @Bean
//    public Queue queue(){
//        return new Queue(orderQueueName());
//    }
//
//    @Bean
//    Binding bindingExchangeMessage(Queue queue, FanoutExchange exchange) {
//        return BindingBuilder.bind(queue).to(exchange);
//    }
//
//    @Bean
//    public SimpleMessageListenerContainer messageListenerContainer(
//            OrderReceiver orderReceiver,
//            @Qualifier("rabbitConnectionFactory") CachingConnectionFactory cachingConnectionFactory){
//        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cachingConnectionFactory);
//        // 监听队列的名称
//        container.setQueueNames(orderQueueName());
//        container.setExposeListenerChannel(true);
//        // 设置每个消费者获取的最大消息数量
//        container.setPrefetchCount(100);
//        // 消费者的个数
//        container.setConcurrentConsumers(1);
//        // 设置确认模式为自动确认
//        container.setAcknowledgeMode(AcknowledgeMode.AUTO);
//        container.setMessageListener(orderReceiver);
//        return container;
//    }
//
//
//    /**
//     * 在这里写获取订单队列名的具体过程
//     * @return
//     */
//    public String orderQueueName(){
//        return "orderChannel";
//    }
}

